package top.jbxie.raft.current;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * raft线程异常捕获
 */
public class RaftThread extends Thread {
    private static final Logger LOGGER = LoggerFactory.getLogger(RaftThread.class);
    // 在Thread ApI中提供的UncaughtExceptionHandle，它能检测出某个由于未捕获的异常而终结的情况，有效地防止线程泄露问题。
    // uncaughtException(Thread t, Throwable e)；
    private static final UncaughtExceptionHandler uncaughtExceptionHandler = (t, e)
            -> LOGGER.warn("Exception occurred from thread {}", t.getName(), e);

    public RaftThread(String threadName,  Runnable r) {
        super(r, threadName);
        setUncaughtExceptionHandler(uncaughtExceptionHandler);
    }
}
